﻿$().ready(function () {

    //去支付按钮
    $(".buy-submit-button").click(function () {
        $("#payResultModal").modal("show");
        document.forms[0].submit();
    });

    $(".modal-close").click(function () {
        $("#payResultModal").modal("hide");
    });

    $(".payResultFailedBtn").click(function () {
        $("#notPayedModal").modal("hide");
    });

    $("#notPayedClose").click(function () {
        $("#notPayedModal").modal("hide");
    });

    
    //点击已完成支付按钮
    $("#pay-already-payed").click(function () {
        var subscriptionID = $("#pay-already-payed").attr("subscriptionID");
        $.post("/course/isbuyer", { subscriptionID: subscriptionID }, function (data) {
            var dataObj = JSON.parse(data);

            if (dataObj.Status == "success" && dataObj.Message == "ok") {
                if (dataObj.Data == "no") {
                    $("#payResultModal").modal("hide");
                    $("#notPayedModal").modal("show");
                }
                else {
                    $("#payResultModal").modal("hide");
                    document.location.href = "/member/pay_success?tradeNo=" + $("#data-trade-no").val();
                }
            }
        })
    });



    //patrick.pan添加
    $('#selectCoupon').change(function () {

        //获取课程价格
        var coursePrice = parseInt($('#coursePrice').val());

        //获取优惠券面值
        var faceValue = parseInt($('#selectCoupon > option:selected').attr("data-faceValue"));

        //用户应付金额
        var totalFee = coursePrice - faceValue;

        $('#payBtn').val("去支付（" + totalFee + "）元");


    });
});